home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 8501 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.5 KB

  1. Path: nwlink.com!usenet
  2. From: tjr19@mail.nwlink.com
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Permutations
  5. Date: 4 Mar 1996 19:01:57 GMT
  6. Organization: Northwest Link
  7. Message-ID: <4hfen5$8uf@texas.nwlink.com>
  8. References: <Dn8yz9.GGy@spuddy.mew.co.uk> <4h1v27$cdc@texas.nwlink.com> <4h4rbn$7es@hpbblb.bbn.hp.com>
  9. NNTP-Posting-Host: port3.annex4.nwlink.com
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 1.2 (Windows; U; 16bit)
  14.  
  15. Matthias Dittrich <matti> wrote:
  16. >Teresa Reiko <tjr19@mail.nwlink.com> wrote:
  17. >>david@spuddy.mew.co.uk (David Turner) wrote:
  18. >>
  19. >>> Does anyone know of an algorithm that works out the different permutations
  20. >>>of ordering a number of objects? Not calculating how many there are, but 
  21. >>>actaully working out (quickly?) what they permutations are!
  22. >>
  23. >>Untested code -- but this should work...
  24. >>Example:  Permute("", "abcdef", 6)
  25. >>
  26. >>void Permute(char *p_prefix, char *p_list, int num)
  27. >>{
  28. >>        int i;
  29. >>    char s[10], p[10];
  30. >>
  31. >>    if(num == 0)
  32. >>    {
  33. >>        printf("%s%s", prefix, p_list);
  34.  
  35. >Here is a little bug:          ^^^^^^
  36. >you mean p_prefix I think.
  37. >
  38. >(And the output is more readable if you append \n to the format string 
  39. > :-)
  40.  
  41. Yep, you're right.  Oops.
  42.  
  43. >>        return;
  44. >>    }
  45. >>
  46. >>    for(i = 0; i < num; i++)
  47. >>  < etc etc etc . . . >    
  48.  
  49. ----------------------------------------------------------------------
  50. Teresa Reiko    Chief Programmer, Tenbyte Software    tjr19@nwlink.com
  51. ----------------------------------------------------------------------
  52.  
  53.  
  54.